package com.aaa.controller.sas;

import com.aaa.controller.BaseController;
import com.aaa.entity.PageSortEntity;
import com.aaa.entity.sas.QuestionSas;
import com.aaa.entity.Result;
import com.aaa.service.sas.QuestionSasService;
import com.github.pagehelper.Page;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 问题表(QuestionSas)表控制层
 *
 * @author makejava
 * @since 2022-08-30 16:14:17
 */
@RestController
@RequestMapping("questionSas")
public class QuestionSasController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private QuestionSasService questionSasService;

    /**
     * 分页查询
     *
     * @param pageSortEntity
     * @param questionSas
     * @return
     */
    @RequestMapping("/questionSasAll.do")
    public Result personalityAllfpa(PageSortEntity pageSortEntity, QuestionSas questionSas) {
        Page<QuestionSas> page = questionSasService.queryQuestionPage(pageSortEntity, questionSas);
        return success(page.getResult(), page.getTotal());
    }


    @RequestMapping("/questionSasPage.do")
    public Result questionSasPage(PageSortEntity pageSortEntity, QuestionSas questionSas) {
        List<QuestionSas> sasList = questionSasService.queryAllQuestion(questionSas);
        Page<QuestionSas> page = (Page) sasList;
        return success(page.getResult(), page.getTotal());
    }


    /**
     * 添加
     *
     * @param questionSas
     * @return
     */
    @RequestMapping(value = "/saveQuestion.do")
    public Result saveQuestion(QuestionSas questionSas) {
        boolean b = questionSasService.saveQuestion(questionSas);
        if (b) {
            return success();
        } else {
            return fail();
        }
    }


    /**
     * 通过ID删除、批量删除
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "questionSasDel.do")
    public Result delQuestion(int[] id) {
        int i = questionSasService.delQuestion(id);
        if (i > 0) {
            return success();
        } else {
            return fail();
        }
    }

    /**
     * 修改
     *
     * @param questionSas
     * @return
     */
    @RequestMapping("questionSasUpdate.do")
    public Result updateQuestion(QuestionSas questionSas) {
        boolean update = questionSasService.update(questionSas);
        if (update) {
            return success();
        } else {
            return fail();
        }
    }


    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<QuestionSas> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.questionSasService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param questionSas 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<QuestionSas> add(QuestionSas questionSas) {
        return ResponseEntity.ok(this.questionSasService.insert(questionSas));
    }


}

